﻿using EntityModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class LivebroadcastController : ControllerBase
    {
        private readonly BitDbContext P;

        public LivebroadcastController(BitDbContext bit)
        {
            P = bit;
        }
        [HttpGet]
        public Result Get()
        {
            Result result = new Result();
            result.Data = P.EM_Livebroadcasts.ToList();
            return result;
        }

        /// <summary>
        /// 查找
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// 

        [HttpGet("{id}")]
        public Result GetT(Guid id)
        {

            Result result = new Result();
            result.Data = P.EM_Livebroadcasts.Where(w => w.ID == id).ToList();
            return result;
        }




        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="act"></param>
        /// <returns></returns>
        [HttpPut]
        public Result UP([FromBody] EM_Livebroadcast act)
        {
            Result result = new Result();
            P.EM_Livebroadcasts.Update(act);
            result.Data = P.SaveChanges();
            return result;
        }



        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public Result DelUser(Guid id)
        {
            Result result = new Result();
            EM_Livebroadcast? user = P.EM_Livebroadcasts.Where(w => w.ID == id).SingleOrDefault();
            if (user != null)
                P.EM_Livebroadcasts.Remove(user);
            result.Data = P.SaveChanges();
            return result;
        }
        /// <summary>
        /// 增加广告
        /// </summary>
        /// <param name="ware"></param>
        /// <returns></returns>
        [HttpPost]
        public Result AddWare([FromBody] EM_Livebroadcast ware)
        {
            Result result = new Result();
            P.EM_Livebroadcasts.Add(ware);
            result.Data = P.SaveChanges();
            return result;
        }



    }
}
